/*
 * @Author: zhouzhe 
 * @Date: 2018-09-22 21:24:10 
 * @Description: '常用工具函数' 
 * @Last Modified by: zhouzhe
 * @Last Modified time: 2018-09-23 00:56:46
 */

 const T = {
     /**
      *  日期时间戳 转 时间格式 
      *   type = 1  yyyy.mm.dd
      *   type = 2  yyyy年mm月dd日 hh:mm
      * **/
     formatDate: (time, type = 1) => {
        if (time === null) {
            return '无数据';
        }
        let date = new Date(time);

        let year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate(),
            hour = date.getHours(),
            min = date.getMinutes(),
            sec = date.getSeconds();
        
        if (type == 1) {
            return `${year}.${month}.${day}`;
        } else if (type == 2) {
            return `${year}年${month}月${day}日 ${hour < 10 ? '0' + hour : hour}:${min < 10 ? '0' + min : min}`;
        }
    }
 };

 export default T;